package com.qingcloud.adminbackend.base;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * vue-table2响应分页数据
 */
public class Vuetable2PageData implements Serializable {

    @ApiModelProperty(value = "数据总数", example = "47")
    private Long total;

    @ApiModelProperty(value = "每页条数", example = "10")
    private Integer per_page;

    @ApiModelProperty(value = "当前页码，从1开始", example = "1")
    private Integer current_page;

    @ApiModelProperty(value = "最后一页页码", example = "5")
    private Integer last_page;

    @ApiModelProperty(value = "当前页数据起始位置", example = "1")
    private Integer from;

    @ApiModelProperty(value = "当前页数据起始位置", example = "2")
    private Long to;

    public Vuetable2PageData() {
    }

    public Vuetable2PageData(Long total, Integer per_page, Integer current_page) {
        this.total = total;
        this.per_page = per_page;
        this.current_page = current_page;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Integer getPer_page() {
        return per_page;
    }

    public void setPer_page(Integer per_page) {
        this.per_page = per_page;
    }

    public Integer getCurrent_page() {
        return current_page;
    }

    public void setCurrent_page(Integer current_page) {
        this.current_page = current_page;
    }

    public Integer getLast_page() {
        return BigDecimal.valueOf(Math.ceil(total / (double) per_page)).intValue();
    }

    public Integer getFrom() {
        if (total != null && total.equals(0L)) return 0;
        return (current_page - 1) * per_page + 1;
    }

    public Long getTo() {
        return Math.min((long)current_page * per_page, total);
    }
}
